package com.feihong.txgw.tx_precenter;

import android.os.Bundle;

import com.feihong.txgw.inter.contract.kaika.ISubscribeKaikaContract;
import com.feihong.txgw.model.bean.kaika.YuyueViewShowEnity;
import com.feihong.txgw.tx_model.SubscribeKaikaMainModel;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName SubscribeKaikaMainPrecenter
 * @package com.feihong.txgw.tx_precenter
 * @data 2018/5/7 12:22
 * @Describe
 * @Change
 */
public class SubscribeKaikaMainPrecenter extends ISubscribeKaikaContract.AbSubscribeKaikaPrecenter {

    public static SubscribeKaikaMainPrecenter create(){
        return new SubscribeKaikaMainPrecenter();
    }

    @Override
    public void submitOrder(String specID, String phoneNum, String adrID, String deliveryType) {
        mIModel.submitOrder(specID,phoneNum,adrID,deliveryType).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(String o) {
                mIView.submitOrderResult(o);
            }

            @Override
            public void onError(Throwable e) {
                mIView.loadDataError();
            }

            @Override
            public void onComplete() {
                mIView.loadDataComplated();
            }
        });
    }

    @Override
    public void parseIntentAndGetDefAdr(Bundle bundle) {
        mIModel.parseBundleAndGetAdr(bundle).subscribe(new Consumer<YuyueViewShowEnity>() {
            @Override
            public void accept(YuyueViewShowEnity yuyueViewShowEnity) throws Exception {
                mIView.viewSetValue(yuyueViewShowEnity);
            }
        });
    }

    @Override
    public void getNewAdr() {
        mIModel.getNewAdr().subscribe(new Consumer<YuyueViewShowEnity>() {
            @Override
            public void accept(YuyueViewShowEnity yuyueViewShowEnity) throws Exception {
                mIView.setNewAdr(yuyueViewShowEnity.getAdress(),yuyueViewShowEnity.getAdressID());
            }
        });
    }

    @Override
    public ISubscribeKaikaContract.ISubscribeKaikaMainModel getModel() {
        return SubscribeKaikaMainModel.create();
    }

    @Override
    public void onStart() {

    }
}
